package org.neptune.service.service.impl;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.neptune.api.entity.Seckill;
import org.neptune.api.entity.SeckillExample;
import org.neptune.api.request.SeckillRequest;
import org.neptune.service.dao.SeckillMapper;
import org.neptune.service.service.SeckillGoodsInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author lwl
 * @date 2019/7/16 13:28
 */
@Service
public class SeckillGoodsInfoServiceImpl implements SeckillGoodsInfoService {

	@Autowired
	private SeckillMapper seckillMapper;

	@Override
	public List<Seckill> querySeckillGoods(SeckillRequest seckillRequest) {

		return seckillMapper.selectByExample(this.getQueryExample(seckillRequest));
	}

	@Override
	public long querySeckillCount(SeckillRequest seckillRequest) {

		return seckillMapper.countByExample(this.getQueryExample(seckillRequest));
	}

	@Override
	public Seckill querySeckillGoodsInfo(SeckillRequest seckillRequest) {
		return null;
	}

	private SeckillExample getQueryExample(SeckillRequest seckillRequest) {
		SeckillExample example = new SeckillExample();
		SeckillExample.Criteria criteria = example.createCriteria();
		if (StringUtils.isNotBlank(seckillRequest.getSeckillGoodsName())){
			criteria.andNameEqualTo(seckillRequest.getSeckillGoodsName());
		}
		return example;
	}
}
